var config = require("core/config");
var host = config.host;

var homemaking = host + "/homemaking";

var baseUrl = homemaking + "/base";
var typeUrl = homemaking + "/type";
var pubitemUrl = homemaking + "/pubitem";
var timeUrl = homemaking + "/time";
var orderUrl = homemaking + "/order";
var imgMax = 3;

module.exports.url = {
	base : {
		page : baseUrl + "/page",
		index : baseUrl + "/index",
		add : baseUrl + "/add",
		detail : baseUrl + "/detail",
		myPage : baseUrl + "/myPage",
		toEdit : baseUrl + "/toEdit",
		edit : baseUrl + "/edit",
		open : baseUrl + "/open",
		close : baseUrl + "/close",
		toOrder : baseUrl + "/toOrder",
		typePage : baseUrl + "/typePage",
		getCanServiceMemberCount : baseUrl + "/getCanServiceMemberCount",
		getCanServiceMemberList : baseUrl + "/getCanServiceMemberList",
		getCanServiceMemberOne : baseUrl + "/getCanServiceMemberOne",
		getCount : baseUrl + "/getCount"
	},
	type : {
		findParent : typeUrl + "/findParent",
		findChildren : typeUrl + "/findChildren",
		indexType : typeUrl + "/indexType",
		detailType : typeUrl + "/detailType"
	},
	pubitem : {
		findByTypeId : pubitemUrl + "/findByTypeId"
	},
	time : {
		findByDate : timeUrl + "/findByDate",
		findByDateAndType : timeUrl + "/findByDateAndType",
		addRestTime : timeUrl + "/addRestTime"
	},
	order : {
		add : orderUrl + "/add",
		myPage : orderUrl + "/myPage",
		completeService : orderUrl + "/completeService"
	}
};

module.exports.typeId = {
	/** 日常保洁id */
	DailyCleaning : 16,
	/** 送水id */
	SongShui : 25,
	/** 家电维修id */
	JiaDianWeiXiu : 17,
	/** 家电清洗id */
	JiaDianQingXi : 1
};

/**
 * ';'分隔图片字符串,转变成[{source:imgs[j],imgCount:""}]格式
 * 
 * @isShowAll:是否显示图片总数量，imgCount:共x张
 * @imgStr:img';'分隔图片字符串
 * @callback:回调函数
 */
var imgFormatFun = function(isShowAll, imgStr) {
	var imgs = imgStr.split(";");
	if (imgs.length > 0) {
		// 图片的数据
		var jsonImgs = [];
		var imgsL = imgs.length;
		if (imgsL >imgMax&&isShowAll) {
			imgsL = imgMax;
		}
		// 图片的数据
		for (var j = 0; j < imgsL; j++) {
			if (j == (imgsL - 1)&&isShowAll) {
				jsonImgs.push({
					source : imgs[j],
					imgCount : "共" + imgs.length + "张"
				});
			} else {
				jsonImgs.push({
					source : imgs[j],
					imgCount : ""
				});
			}
		}
		return jsonImgs;
	}
}
module.exports.fun = {
		img : {
			format : imgFormatFun
		}
};
